
export const getDeptTreeData = function(data){    //序列化部门树形结构
  var list = data.filter((item)=>{
    return item.id == 0
  })
  var plist = data.filter((item)=>{
    return item.pId == 0 && item.id != 0
  })
  plist.forEach(element => {
    var childrenList = data.filter((item)=>{
      return item.pId == element.id
    })
    element.children = childrenList
  });
  list[0].children = plist
  return list
}

export const getMenuTreeData = function(data,pId = 0){    //序列化菜单树形结构
  const temp = [];
  for (const item of data) {
    if (item.pId === pId && item.id != 0) {
      item.children = getMenuTreeData(data,item.id);
      temp.push(item);
    }
  }
  return temp;
}

export const getDictTreeData = function(data,pId = 0){    //序列化字典树形结构
  const temp = [];
  for (const item of data) {
    if (item.pId === pId && item.id != 0) {
      item.children = getMenuTreeData(data,item.id);
      temp.push(item);
    }
  }
  return temp;
}

export const getMenuTreeDataByLevel = function(data,pcode = "0"){    //序列化菜单树形结构
  const temp = [];
  for (const item of data) {
    item.id = item.menuId
    if (item.pcode === pcode) {
      item.children = getMenuTreeDataByLevel(data,item.code);
      temp.push(item);
    }
  }
  return temp;
}

export const exportToExcel = function(columns,list,title){
  require.ensure([], () => {
    const { export_json_to_excel } = require('../excel/Export2Excel');
    let tHeader = []
    let filterVal = []
    columns.forEach(item =>{
        tHeader.push(item.title)
        filterVal.push(item.key)
    })
    const data = list.map(v => filterVal.map(j => v[j]))
    export_json_to_excel(tHeader, data, title);
})
}
